import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";

const routes = [
    {
        path: '/',
        redirect: '/dashboard'
    }, {
        path: "/",
        name: "Home",
        component: Home,
        children: [
            {
                path: "/dashboard",
                name: "dashboard",
                meta: {
                    title: '系统首页'
                },
                component: () => import(
                    /* webpackChunkName: "dashboard" */
                    "../views/Dashboard.vue")
            },
            //  {
            //     path: "/table",
            //     name: "basetable",
            //     meta: {
            //         title: '表格'
            //     },
            //     component: () => import(
            //         /* webpackChunkName: "table" */
            //         "../views/BaseTable.vue")
            // }, {
            //     path: "/charts",
            //     name: "basecharts",
            //     meta: {
            //         title: '图表'
            //     },
            //     component: () => import(
            //         /* webpackChunkName: "charts" */
            //         "../views/BaseCharts.vue")
            // }, {
            //     path: "/form",
            //     name: "baseform",
            //     meta: {
            //         title: '表单'
            //     },
            //     component: () => import(
            //         /* webpackChunkName: "form" */
            //         "../views/BaseForm.vue")
            // }, {
            //     path: "/tabs",
            //     name: "tabs",
            //     meta: {
            //         title: 'tab标签'
            //     },
            //     component: () => import(
            //         /* webpackChunkName: "tabs" */
            //         "../views/Tabs.vue")
            // },

            //新增
            // {
            //     path: '/trafficAgent',
            //     name: 'trafficAgent',
            //     meta: {
            //         title: '话务管理'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/trafficAgent.vue')
            // },
            // {
            //     path: '/app',
            //     name: 'app',
            //     meta: {
            //         title: '应用'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/app.vue')
            // },
            // {
            //     path: '/xnum',
            //     name: 'xnum',
            //     meta: {
            //         title: 'x号码'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/xnum.vue')
            // },
            // {
            //     path: '/xnumimport',
            //     name: 'xnumimport',
            //     meta: {
            //         title: 'x号码导入'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/xnumimport.vue')
            // },

            //呼叫中心
            {
                path: '/agent',
                name: 'agent',
                meta: {
                    title: '代理管理'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/agent.vue')
            },
            {
                path: '/enterprise',
                name: 'enterprise',
                meta: {
                    title: '企业管理'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/enterprise.vue')
            },
            {
                path: '/callLog',
                name: 'callLog',
                meta: {
                    title: '通话记录'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/callLog.vue')
            },
            {
                path: '/centerNum',
                name: 'centerNum',
                meta: {
                    title: '移动4中间号管理'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/centerNum.vue')
            },
            {
                path: '/dailyReport',
                name: 'dailyReport',
                meta: {
                    title: '话单日报表'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/dailyReport.vue')
            },
            {
                path: '/monthlyReport',
                name: 'monthlyReport',
                meta: {
                    title: '月报表'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/monthlyReport.vue')
            },
            {
                path: '/lt2NumManage',
                name: 'lt2NumManage',
                meta: {
                    title: '联通2号码管理'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/lt2NumManage.vue')
            },
            // {
            //     path: '/exportImportUser',
            //     name: 'exportImportUser',
            //     meta: {
            //         title: '导出导入用户'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/exportImportUser.vue')
            // },
            // {
            //     path: '/accountMigration',
            //     name: 'accountMigration',
            //     meta: {
            //         title: '账户迁移'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/accountMigration.vue')
            // },
            {
                path: '/seats',
                name: 'seats',
                meta: {
                    title: '坐席管理'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/seats.vue')
            },
            // {
            //     path: '/rechargeMassage',
            //     name: 'rechargeMassage',
            //     meta: {
            //         title: '充值信息'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/rechargeMassage.vue')
            // },
            // {
            //     path: '/consumptionReport',
            //     name: 'consumptionReport',
            //     meta: {
            //         title: '企业消费报表'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/consumptionReport.vue')
            // },
            // {
            //     path: '/gatewayChargeReport',
            //     name: 'gatewayChargeReport',
            //     meta: {
            //         title: '网关消费报表'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/gatewayChargeReport.vue')
            // },
            // {
            //     path: '/callListControl',
            //     name: 'callListControl',
            //     meta: {
            //         title: '话单监控'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/callListControl.vue')
            // },
            {
                path: '/audit',
                name: 'audit',
                meta: {
                    title: '企业申请'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/audit.vue')
            },
            // {
            //     path: '/stopMassage',
            //     name: 'stopMassage',
            //     meta: {
            //         title: '挂机短信'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/stopMassage.vue')
            // },
            {
                path: '/enterpriseRecharge',
                name: 'enterpriseRecharge',
                meta: {
                    title: '企业充值信息'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/enterpriseRecharge.vue')
            },
            {
                path: '/agentRecharge',
                name: 'agentRecharge',
                meta: {
                    title: '代理充值信息'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/agentRecharge.vue')
            },
            {
                path: '/agentManagement',
                name: 'agentManagement',
                meta: {
                    title: '联通AX亲情管理'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/agentManagement.vue')
            },
            // {
            //     path: '/userRecharge',
            //     name: 'userRecharge',
            //     meta: {
            //         title: '用户充值'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/userRecharge.vue')
            // },
            // {
            //     path: '/enterpriseBalance',
            //     name: 'enterpriseBalance',
            //     meta: {
            //         title: '企业余额'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/enterpriseBalance.vue')
            // },
            {
                path: '/lt4NumManage',
                name: 'lt4NumManage',
                meta: {
                    title: '联通4号码管理'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/lt4NumManage.vue')
            },

            //系统管理
            // {
            //     path: '/resetPassword',
            //     name: 'resetPassword',
            //     meta: {
            //         title: '修改密码'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/resetPassword.vue')
            // },


            //山东移动
            // {
            //     path: '/accountAdmin',
            //     name: 'accountAdmin',
            //     meta: {
            //         title: '账户管理'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/accountAdmin.vue')
            // },
            // {
            //     path: '/appAdmin',
            //     name: 'appAdmin',
            //     meta: {
            //         title: '应用管理'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/appAdmin.vue')
            // },
            // //YSH
            // {
            //     path: '/app1',
            //     name: 'app1',
            //     meta: {
            //         title: '应用'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/app1.vue')
            // },
            // {
            //     path: '/nums',
            //     name: 'nums',
            //     meta: {
            //         title: '号码池'
            //     },
            //     component: () => import(/* webpackChunkName: "404" */
            //         '../views/nums.vue')
            // },
        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import(
            /* webpackChunkName: "login" */
            "../views/Login.vue")
    },
    {
        path: "/403",
        name: "403",
        meta: {
            title: '无权限'
        },
        component: () => import(
            /* webpackChunkName: "login" */
            "../views/403.vue")
    },
    {
        path: "/404",
        name: "404",
        meta: {
            title: '页面不存在'
        },
        component: () => import(
            /* webpackChunkName: "login" */
            "../views/404.vue")
    }
];

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes,
});

router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | 大迈通后台管理系统`;
    const role = localStorage.getItem('ms_username');
    if (!role && to.path !== '/login') {
        next('/login');
    } else if (to.meta.permission) {
        // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
        role === 'admin'
            ? next()
            : next('/403');
    } else {
        next();
    }
});

export default router;